package cn.masterj.springcloud.service.impl;

import cn.masterj.springcloud.service.CustomMessageChannel;
import cn.masterj.springcloud.service.IProviderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.messaging.Source;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.support.MessageBuilder;

import java.util.UUID;

/**
 * @author masterJ
 * @create 2020-04-15 21:24
 */
@EnableBinding({Source.class, CustomMessageChannel.class})
public class ProviderServiceImpl implements IProviderService {

    @Autowired
    @Qualifier(Source.OUTPUT)
    private MessageChannel output;

    /**
     * 注入自定义目的地的管道
     */
    @Autowired
    @Qualifier("customDestination")
    private MessageChannel customMessageChannel;

    @Override
    public String send() {
        String serial = UUID.randomUUID().toString();
        output.send(MessageBuilder.withPayload(serial).build());
        customMessageChannel.send(MessageBuilder.withPayload(serial).build());
        return serial;
    }
}
